package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Device;
import com.example.entity.DeviceOperation;
import com.example.service.DeviceOperationService;
import com.example.mapper.DeviceOperationMapper;
import com.example.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author luo20
* @description 针对表【device_operation(设备操作记录表)】的数据库操作Service实现
* @createDate 2025-06-23 10:13:28
*/
@Service
public class DeviceOperationServiceImpl extends ServiceImpl<DeviceOperationMapper, DeviceOperation>
    implements DeviceOperationService{
    
    @Autowired
    private DeviceOperationMapper deviceOperationMapper;
    
    @Override
    public PageResult<DeviceOperation> pageDeviceOperation(Integer deviceId) {
        // 开启分页
        PageHelper.startPage(1, 5);
        // 根据条件查询
        LambdaQueryWrapper<DeviceOperation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DeviceOperation::getDeviceId,deviceId);
        
        List<DeviceOperation> deviceOperationList = deviceOperationMapper.selectList(queryWrapper);
        //分页
        Page<DeviceOperation> devicePage = (Page<DeviceOperation>) deviceOperationList;
        //返回数据
        return PageResult.<DeviceOperation>builder().total(devicePage.getTotal()).rows(devicePage.getResult()).build();
    }
}




